import { defineComponent as g, ref as d, shallowRef as C, onMounted as E, watch as y, watchEffect as P, toRaw as O, openBlock as h, createElementBlock as w } from "vue";
import { c as $, r as b, a as F } from "./index-3bf51563.mjs";
import "./e-s-alert-dd48c22c.mjs";
var B = Object.defineProperty, D = Object.defineProperties, j = Object.getOwnPropertyDescriptors, m = Object.getOwnPropertySymbols, H = Object.prototype.hasOwnProperty, S = Object.prototype.propertyIsEnumerable, _ = (e, t, o) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, A = (e, t) => {
  for (var o in t || (t = {}))
    H.call(t, o) && _(e, o, t[o]);
  if (m)
    for (var o of m(t))
      S.call(t, o) && _(e, o, t[o]);
  return e;
}, M = (e, t) => D(e, j(t));
function a(e) {
  let t = `请使用 '@${e}' 事件，不要放在 props 中`;
  return t += `
Please use '@${e}' event instead of props`, t;
}
var v = (e, t) => {
  for (const [o, u] of t)
    e[o] = u;
  return e;
};
const V = g({
  props: {
    mode: {
      type: String,
      default: "default"
    },
    defaultContent: {
      type: Array,
      default: []
    },
    defaultHtml: {
      type: String,
      default: ""
    },
    defaultConfig: {
      type: Object,
      default: {}
    },
    modelValue: {
      type: String,
      default: ""
    }
  },
  setup(e, t) {
    const o = d(null), u = C(null), i = d(""), s = () => {
      if (!o.value)
        return;
      const l = O(e.defaultContent);
      $({
        selector: o.value,
        mode: e.mode,
        content: l || [],
        html: e.defaultHtml || e.modelValue || "",
        config: M(A({}, e.defaultConfig), {
          onCreated(r) {
            if (u.value = r, t.emit("onCreated", r), e.defaultConfig.onCreated) {
              const n = a("onCreated");
              throw new Error(n);
            }
          },
          onChange(r) {
            const n = r.getHtml();
            if (i.value = n, t.emit("update:modelValue", n), t.emit("onChange", r), e.defaultConfig.onChange) {
              const f = a("onChange");
              throw new Error(f);
            }
          },
          onDestroyed(r) {
            if (t.emit("onDestroyed", r), e.defaultConfig.onDestroyed) {
              const n = a("onDestroyed");
              throw new Error(n);
            }
          },
          onMaxLength(r) {
            if (t.emit("onMaxLength", r), e.defaultConfig.onMaxLength) {
              const n = a("onMaxLength");
              throw new Error(n);
            }
          },
          onFocus(r) {
            if (t.emit("onFocus", r), e.defaultConfig.onFocus) {
              const n = a("onFocus");
              throw new Error(n);
            }
          },
          onBlur(r) {
            if (t.emit("onBlur", r), e.defaultConfig.onBlur) {
              const n = a("onBlur");
              throw new Error(n);
            }
          },
          customAlert(r, n) {
            if (t.emit("customAlert", r, n), e.defaultConfig.customAlert) {
              const f = a("customAlert");
              throw new Error(f);
            }
          },
          customPaste: (r, n) => {
            if (e.defaultConfig.customPaste) {
              const c = a("customPaste");
              throw new Error(c);
            }
            let f;
            return t.emit("customPaste", r, n, (c) => {
              f = c;
            }), f;
          }
        })
      });
    };
    function p(l) {
      const r = u.value;
      r != null && r.setHtml(l);
    }
    return E(() => {
      s();
    }), y(() => e.modelValue, (l) => {
      l !== i.value && p(l);
    }), {
      box: o
    };
  }
}), L = {
  ref: "box",
  style: { height: "100%" }
};
function T(e, t, o, u, i, s) {
  return h(), w("div", L, null, 512);
}
var z = /* @__PURE__ */ v(V, [["render", T]]);
const I = g({
  props: {
    editor: {
      type: Object
    },
    mode: {
      type: String,
      default: "default"
    },
    defaultConfig: {
      type: Object,
      default: {}
    }
  },
  setup(e) {
    const t = d(null), o = (u) => {
      if (t.value) {
        if (u == null)
          throw new Error("Not found instance of Editor when create <Toolbar/> component");
        b.getToolbar(u) || F({
          editor: u,
          selector: t.value || "<div></div>",
          mode: e.mode,
          config: e.defaultConfig
        });
      }
    };
    return P(() => {
      const { editor: u } = e;
      u != null && o(u);
    }), {
      selector: t
    };
  }
}), R = { ref: "selector" };
function x(e, t, o, u, i, s) {
  return h(), w("div", R, null, 512);
}
var G = /* @__PURE__ */ v(I, [["render", x]]);
export {
  z as Editor,
  G as Toolbar
};
